﻿namespace Sidvall.WorkItemManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class WebTarget : global::Sidvall.WorkItemManager.UI.Entities.Core.BusinessBase, global::Sidvall.WorkItemManager.Data.IWebTarget
    {
        #region Business Members

        #region Content

        private string _Content = string.Empty;
        partial void OnBeforeContentPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeContentPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterContentPropertyChanged();
        public string Content
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Content);
                OnBeforeContentPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Content);
                OnBeforeContentPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Content", eventData.Value, true, true, true);
                    OnAfterContentPropertyChanged();
                }
            }
        }

        #endregion
        #region HttpVerb

        private string _HttpVerb = string.Empty;
        partial void OnBeforeHttpVerbPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeHttpVerbPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterHttpVerbPropertyChanged();
        public string HttpVerb
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_HttpVerb);
                OnBeforeHttpVerbPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _HttpVerb);
                OnBeforeHttpVerbPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("HttpVerb", eventData.Value, true, true, true);
                    OnAfterHttpVerbPropertyChanged();
                }
            }
        }

        #endregion
        #region IsEnabled

        private bool _IsEnabled = false;
        partial void OnBeforeIsEnabledPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeIsEnabledPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsEnabledPropertyChanged();
        public bool IsEnabled
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_IsEnabled);
                OnBeforeIsEnabledPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsEnabled);
                OnBeforeIsEnabledPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("IsEnabled", eventData.Value, true, true, true);
                    OnAfterIsEnabledPropertyChanged();
                }
            }
        }

        #endregion
        #region WebAddress

        private string _WebAddress = string.Empty;
        partial void OnBeforeWebAddressPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeWebAddressPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterWebAddressPropertyChanged();
        public string WebAddress
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_WebAddress);
                OnBeforeWebAddressPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _WebAddress);
                OnBeforeWebAddressPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WebAddress", eventData.Value, true, true, true);
                    OnAfterWebAddressPropertyChanged();
                }
            }
        }

        #endregion
        #region WebContextId

        private int _WebContextId = 0;
        partial void OnBeforeWebContextIdPropertyGet(Sidvall.Business.PropertyEventData<int> eventData);
        partial void OnBeforeWebContextIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<int> eventData);
        partial void OnAfterWebContextIdPropertyChanged();
        public int WebContextId
        {
            get
            {
                Sidvall.Business.PropertyEventData<int> eventData = new Sidvall.Business.PropertyEventData<int>(_WebContextId);
                OnBeforeWebContextIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<int> eventData = new Sidvall.Business.PropertyChangeEventData<int>(value, _WebContextId);
                OnBeforeWebContextIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WebContextId", eventData.Value, true, true, true);
                    OnAfterWebContextIdPropertyChanged();
                }
            }
        }

        #endregion
        #region WebTargetId

        private System.Nullable<int> _WebTargetId = null;
        partial void OnBeforeWebTargetIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData);
        partial void OnBeforeWebTargetIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterWebTargetIdPropertyChanged();
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public System.Nullable<int> WebTargetId
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<int>>(_WebTargetId);
                OnBeforeWebTargetIdPropertyGet(eventData);
                return eventData.Value;
            }
            internal set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _WebTargetId);
                OnBeforeWebTargetIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WebTargetId", eventData.Value, true, true, true);
                    OnAfterWebTargetIdPropertyChanged();
                }
            }
        }

        #endregion
        #region WebContext

        private WebContext _WebContext;
        partial void OnBeforeWebContextPropertyChanged(Sidvall.Business.PropertyChangeEventData<WebContext> eventData);
        partial void OnAfterWebContextPropertyChanged();
        public WebContext WebContext
        {
            get
            {
                return _WebContext;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<WebContext> eventData = new Sidvall.Business.PropertyChangeEventData<WebContext>(value, _WebContext);
                OnBeforeWebContextPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WebContext", eventData.Value, true, true, false);
                    OnAfterWebContextPropertyChanged();
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebTargetManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowIsValid

        public override bool DataRowIsValid(Sidvall.Data.BusinessRuleFilter filter)
        {
            return global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebTargetManager.DataRowIsValid(this, filter);
        }

        #endregion
        #region DataRowStateIsDirty

        public override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebTargetManager.DataRowStateIsDirty(this);
            }
        }

        #endregion

        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebTargetManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebTargetManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public WebTarget Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public WebTarget Copy()
        {
            return Copy(null);
        }
        public WebTarget Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new WebTarget();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IWebTarget item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IWebTarget item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(WebTarget destination, global::Sidvall.WorkItemManager.Data.IWebTarget source, Sidvall.Data.CopySettings copySettings);
        private void Import(WebTarget destination, global::Sidvall.WorkItemManager.Data.IWebTarget source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebTargetManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(WebTarget destination, WebTarget source, Sidvall.Data.CopySettings copySettings);
        private void Import(WebTarget destination, WebTarget source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.WorkItemManager.Data.IWebTarget, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebTargetManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebTargetManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebTargetManager.Initialize(this, settings);
        }

        #endregion
        
        #region IWebTarget Members

        string global::Sidvall.WorkItemManager.Data.IWebTarget.Content
        {
            get
            {
                return this._Content;
            }
            set
            {
                this._Content = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IWebTarget.HttpVerb
        {
            get
            {
                return this._HttpVerb;
            }
            set
            {
                this._HttpVerb = value;
            }
        }
        bool global::Sidvall.WorkItemManager.Data.IWebTarget.IsEnabled
        {
            get
            {
                return this._IsEnabled;
            }
            set
            {
                this._IsEnabled = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IWebTarget.WebAddress
        {
            get
            {
                return this._WebAddress;
            }
            set
            {
                this._WebAddress = value;
            }
        }
        int global::Sidvall.WorkItemManager.Data.IWebTarget.WebContextId
        {
            get
            {
                return this._WebContextId;
            }
            set
            {
                this._WebContextId = value;
            }
        }
        System.Nullable<int> global::Sidvall.WorkItemManager.Data.IWebTarget.WebTargetId
        {
            get
            {
                return this._WebTargetId;
            }
            set
            {
                this._WebTargetId = value;
            }
        }
        global::Sidvall.WorkItemManager.Data.IWebContext global::Sidvall.WorkItemManager.Data.IWebTarget.WebContext
        {
            get
            {
                return this._WebContext;
            }
            set
            {
                UpdateChildProperty(this._WebContext, value);
                this._WebContext = value as WebContext;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public WebTarget()
        {
        }

        public WebTarget(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}